package com.stx.bms.dao;

import com.stx.bms.util.JDBCUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class TransTest {

    public static void main(String[] args) throws SQLException {

        String sql = "insert into t_bms_user values(seq_bms_user.nextval, 'zhanglian', 'admin2', '18888888888', sysdate)";
        String sql2 = "insert into t_buser values(seq_bms_user.nextval, 'shuangtixi', '123456', '18888888888', sysdate)";

        Connection con = JDBCUtil.getCon();
        PreparedStatement ps = null;
        PreparedStatement ps2 = null;

        con.setAutoCommit(false); // 关闭事务的自动提交功能

        try{
            ps = con.prepareStatement(sql);
            ps.execute();

            ps2 = con.prepareStatement(sql2);
            ps2.execute();
        } catch (SQLException e){
            e.printStackTrace();

            con.rollback(); // 手动回滚事务
        }

        con.commit(); // 手动提交事务

        ps.close();
        ps2.close();
        con.close();

    }



}
